package com.leha.forum.lehare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leha.forum.lehare.entity.UserRole;
import com.leha.forum.lehare.service.UserRoleService;
import com.leha.forum.lehare.mapper.UserRoleMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Administrator
* @description 针对表【user_role】的数据库操作Service实现
* @createDate 2025-04-15 21:44:28
*/
@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole>
    implements UserRoleService{

    @Override
    public boolean deleteByRoleId(Integer roleId) {
        if (roleId <= 0) {
            throw new IllegalArgumentException("角色 ID 无效");
        }

        return remove(new QueryWrapper<UserRole>().eq("role_id", roleId));
    }

    @Override
    public List<UserRole> getUserRoles(Long userId) {
        if (userId <= 0) {
            throw new IllegalArgumentException("用户 ID 无效");
        }

        return list(new QueryWrapper<UserRole>().eq("user_id", userId));
    }
}




